<!DOCTYPE html>
<html>
<head>
    <title>医院挂号系统</title>
    <!-- 避免中文乱码 -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
 <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
 <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" >
 <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
 <script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
 <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
 <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
</head>
<body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    getALLRegisterselect()
    function getALLRegisterselect() {
        $.post("/ab", function (data) {
            console.log(data);
            var html = "<>";
            for (let i = 0; i < data.length; i++) {
                let canWork = data[i].register_type === 1 ? "普通门诊" : "急诊";
                html += "<tr>" +
                    "<td>" + data[i].id + "</td>" +
                    "<td>" + data[i].name + "</td>" +
                    "<td>" + data[i].department_name + "</td>" +
                    "<td>" + canWork + "</td>" +
                    "<td>" + data[i].dname + "</td>" +
                    "<td>" + data[i].time + "</td>" +
                    "<td>" + data[i].price_r + "</td>" +
                    "<td>" + `<input type='button' value='删除' class="btn btn-primary" onclick='deleteRegister(${data[i].id})'> ` + "</td>" +
                    "</tr>"
            }
            $("#content").html(html);
        });
    }
    function deleteRegister(id) {
        $.ajax({
            type: "post",
            url: "/j",
            data: JSON.stringify({
                id:id,
            }),
            contentType: "application/json;charset=UTF-8",
            success: function(data){
                getALLRegisterselect();
                alert("删除成功！");
            }
        });
    }
    $(function(){
        $('#btn').click(function(){
            $.ajax({
                type: "post",
                url: "/bc",
                data: JSON.stringify({
                    id:$("#id").val(),
                }),
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function(data){
                    console.log(data);
                    var html="<>";
                    let canWork = data.register_type === 1 ? "普通门诊" : "急诊";
                    html += "<tr>"+
                        "<td>"+data.id+"</td>"+
                        "<td>"+data.name+"</td>"+
                        "<td>"+data.department_name+"</td>"+
                        "<td>"+canWork+"</td>"+
                        "<td>"+data.dname+"</td>"+
                        "<td>"+data.time+"</td>"+
                        "<td>"+data.price_r+"</td>"+
                        "<td>" + `<input type='button' value='删除' class="btn btn-primary" onclick='deleteRegister(${data.id})'> ` + "</td>" +
                        "</tr>"
                    $("#content").html(html);
                },
                error:function (data){
                    alert("查无此人，请核实后再次输入！");
                }
            });
        });
    });

</script>

<div class="container">
          <div class="panel panel-primary">
              <div class="panel-heading">
                  <h3>医院挂号系统</h3>
              </div>
              
              <div class="panel-body">
                  <div class="form-group">
                      <label class="sr-only" >Password</label>
                      <div class="col-sm-5">
                      <input type="text" class="form-control" id="id" name="searchInf" placeholder="输入ID号即可查询">
                     
                      </div>                 
                          <button type="button" class="btn btn-primary" id="btn">查找</button>
                          <button type="button" class="btn btn-primary" onclick="window.location='addRegister.html'">添加</button>
                  </div>
                  <div class="panel-footer" style="height: 490px;overflow: auto;">
                  <table class="table table-striped " id="formTable">
                      <thead>
                          <tr>
                              <th>id号</th>
                              <th>病人姓名</th>
                              <th>科室类型</th>    
                              <th>门诊类型</th>    
                              <th>医生姓名</th>    
                              <th>时间</th>    
                              <th>价钱</th>                            
                              <th>操作</th>
                          </tr>
                      </thead>
                      <tbody id="content">
                    </tbody>
                  </table>
                  </div>
                  <button type="button" class="btn btn-primary" onclick="window.location='selectRegister.html'">返回主页面</button>
              </div>
          </div>
      </div>     
      </body>

</html>
